/**
 * Copyright (c) 2013-2022 Nikita Koksharov
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.redisson.client.protocol.convertor;

import java.util.ArrayList;
import java.util.List;


/**
 * 字符串到列表转换器类，实现了Convertor接口
 * 用于将字符串转换为字符串列表。
 */
public class StringToListConvertor implements Convertor<List<String>> {

    /**
     * 将输入对象转换为字符串列表。
     *
     * @param obj 输入待转换的对象，预期为字符串类型。
     * @return 转换后的字符串列表，每个字符串代表输入字符串中的一行。
     */
    @Override
    public List<String> convert(Object obj) {
        // 将输入对象强制转换为字符串
        String value = (String) obj;
        // 创建一个空列表来存储转换后的字符串
        List<String> result = new ArrayList<String>();
        // 使用正则表达式分割字符串，处理换行符的差异，将每行添加到结果列表中
        for (String entry : value.split("\r\n|\n")) {
            result.add(entry);
        }
        return result;
    }

}
